package kn.cstf2.users.Server;

import kn.cstf2.login.Server.*;
import kn.cstf2.global.Utils.*;
import kn.cstf2.login.Server.*;
import kn.cstf2.global.Utils.CstF2Exception;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import kn.cstf2.users.Bean.UsersBean;


/**
 * @author Izhar Gamaliel Hernandez Cruz Programador Java Junior Desarrollado
 * para Kuehne + Nagel
 */
public class AdaptadorUsers {

  
    public static ArrayList<String> ObternerUsersWithSameNameAndEmail(ResultSet rs) {
        ArrayList<String> users = new ArrayList<String>();
        UsersBean userBean;
        try {
            while (rs.next()) {
                userBean = new UsersBean();
                userBean.setUsername(rs.getString("username"));
                users.add(userBean.getUsername());
            }
        } catch (SQLException ex) {
          
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return users;
    }

    public static ArrayList<UsersBean> ObternerUsersByName(ResultSet rs) {
        ArrayList<UsersBean> users = new ArrayList<UsersBean>();
        UsersBean userBean;
        try {
            while (rs.next()) {
                userBean = new UsersBean();

                userBean.setId(rs.getInt("id"));
                userBean.setUsername(rs.getString("username"));
                userBean.setPwd(rs.getString("pwd"));
                userBean.setEmail(rs.getString("email"));
                userBean.setUsertype(rs.getString("usertype"));
                userBean.setRg(rs.getBoolean("rg"));
                userBean.setRgro(rs.getBoolean("rgro"));
                userBean.setRco(rs.getBoolean("rco"));
                userBean.setRcoro(rs.getBoolean("rcoro"));
                userBean.setCcr(rs.getBoolean("ccr"));
                userBean.setCcrro(rs.getBoolean("ccrro"));
                userBean.setOpc(rs.getBoolean("opc"));
                userBean.setOpcro(rs.getBoolean("opcro"));
                userBean.setMng(rs.getBoolean("mng"));
                userBean.setMngro(rs.getBoolean("mngro"));
                userBean.setSu(rs.getBoolean("su"));

                users.add(userBean);

            }
        } catch (SQLException ex) {
            
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return users;
    }

    public static ArrayList<StringBuilder> ObtenerModificarUsersByName(ResultSet rs) {
        ArrayList<StringBuilder> users = new ArrayList<StringBuilder>();
        StringBuilder userBean = new StringBuilder();;
        
        try {
            while (rs.next()) {
//                userBean.append(rs.getInt("id")+",");
//                userBean.append(rs.getString("username")+",");
//                userBean.append(rs.getString("pwd")+",");
//                userBean.append(rs.getString("email")+",");
//                userBean.append(rs.getString("usertype")+",");
//                userBean.append(rs.getBoolean("rg")+",");
//                userBean.append(rs.getBoolean("rgro")+",");
//                userBean.append(rs.getBoolean("rco")+",");
//                userBean.append(rs.getBoolean("rcoro")+",");
//                userBean.append(rs.getBoolean("ccr")+",");
//                userBean.append(rs.getBoolean("ccrro")+",");
//                userBean.append(rs.getBoolean("opc")+",");
//                userBean.append(rs.getBoolean("opcro")+",");
//                userBean.append(rs.getBoolean("mng")+",");
//                userBean.append(rs.getBoolean("mngro")+",");
//                userBean.append(rs.getBoolean("su"));
//                userBean.append("~");
                
                userBean.append(rs.getInt("id")+",");
                userBean.append(rs.getString("username")+",");
                userBean.append(rs.getString("pwd")+",");
                userBean.append(rs.getString("email")+",");
                userBean.append(rs.getBoolean("transition")+",");
                userBean.append(rs.getBoolean("transitionaccess")+",");
                userBean.append(rs.getBoolean("implementation")+",");
                userBean.append(rs.getBoolean("implementationaccess")+",");
                userBean.append(rs.getBoolean("cop")+",");
                userBean.append(rs.getBoolean("copaccess")+",");
                userBean.append(rs.getBoolean("su"));
                userBean.append("~");
            }
            users.add(userBean);
        } catch (SQLException ex) {
   
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return users;
    }

    public static UsersBean ObternerUsersInfo(ResultSet rs) {

        UsersBean userBean = new UsersBean();
        try {
            while (rs.next()) {
                userBean.setId(rs.getInt("id"));
                userBean.setUsername(rs.getString("username"));
                userBean.setPwd(rs.getString("pwd"));
                userBean.setEmail(rs.getString("email"));
                userBean.setUsertype(rs.getString("usertype"));
            }
        } catch (SQLException ex) {
           
            throw new CstF2Exception("No se pudo obtener la informacion del Usuario");
        }
        return userBean;
    }
}
